package com.rin.design_pattern.abstract_factory;

import com.rin.design_pattern.common.color.Color;
import com.rin.design_pattern.common.color.ColorType;
import com.rin.design_pattern.common.shape.Shape;
import com.rin.design_pattern.common.shape.ShapeType;

/**
 * @author RinMi
 * @since 2023/5/26
 */
public class AbstractFactoryDemo {
    public static void main(String[] args) {
        AbstractFactoryDemo abstractFactoryDemo = new AbstractFactoryDemo();
        abstractFactoryDemo.createFactory(ThemeType.makeRedCircle());
        abstractFactoryDemo.createFactory(ThemeType.makeGreenSquare());
        abstractFactoryDemo.createFactory(ThemeType.makeBlueRectangle());
        abstractFactoryDemo.createFactory(ThemeType.customTheme(ShapeType.RECTANGLE, ColorType.RED));
        abstractFactoryDemo.createFactory(ThemeType.customTheme("star", "yellow"));
    }


    public void createFactory(ThemeType themeType) {
        AbstractFactory factory;
        //绘制图形
        factory = FactoryProducer.getFactory(FactoryType.SHAPE);
        assert factory != null;
        Shape shape = factory.getShape(themeType.getShapeType());
        shape.draw();
        //填充颜色
        factory = FactoryProducer.getFactory(FactoryType.COLOR);
        assert factory != null;
        Color color = factory.getColor(themeType.getColorType());
        color.fill();
    }
}
